﻿using System;
using System.Collections.ObjectModel;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using VivendoByteToolkit.Tile;
using VivendoByteToolkit.Toast;
using Windows.UI.Popups;

namespace VivendoByteToolkit.Sample.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        public RelayCommand IncrementCommand { get; set; }
        public RelayCommand DecrementCommand { get; set; }
        public RelayCommand MultiplyCommand { get; set; }
        public RelayCommand DivideCommand { get; set; }
        public RelayCommand GotFocusCommand { get; set; }
        public RelayCommand LostFocusCommand { get; set; }
        public RelayCommand SelectCommand { get; set; }
        public RelayCommand CreateToastCommand { get; set; }
        public RelayCommand UpdateTileCommand { get; set; }

        public ObservableCollection<int> Values { get; set; }

        int number;
        public int Number
        {
            get
            {
                return number;
            }
            set
            {
                if (value != number)
                {
                    number = value;
                    base.RaisePropertyChanged("Number");
                }
            }
        }

        decimal price;
        public decimal Price
        {
            get
            {
                return price;
            }
            set
            {
                if (value != price)
                {
                    price = value;
                    base.RaisePropertyChanged("Price");
                }
            }
        }

        DateTime date;
        public DateTime Date
        {
            get
            {
                return date;
            }
            set
            {
                if (value != date)
                {
                    date = value;
                    base.RaisePropertyChanged("Date");
                }
            }
        }

        int itemSelected;
        public int ItemSelected
        {
            get
            {
                return itemSelected;
            }
            set
            {
                if (value != itemSelected)
                {
                    itemSelected = value;
                    base.RaisePropertyChanged("ItemSelected");
                }
            }
        }

        string caption;
        public string Caption
        {
            get
            {
                return caption;
            }
            set
            {
                if (value != caption)
                {
                    caption = value;
                    base.RaisePropertyChanged("Caption");
                }
            }
        }

        public MainViewModel()
        {
            this.Number = 10;
            this.Price = 12.34M;
            this.Date = DateTime.Now;
            
            this.Caption = "When this textbox got focus, a command is executed, and a MessageDialog appears on the screen!";
            this.Values = new ObservableCollection<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            this.IncrementCommand = new RelayCommand(IncrementCommandExecute);
            this.DecrementCommand = new RelayCommand(DecrementCommandExecute);
            this.MultiplyCommand = new RelayCommand(MultiplyCommandExecute);
            this.DivideCommand = new RelayCommand(DivideCommandExecute);
            this.GotFocusCommand = new RelayCommand(GotFocusCommandExecute);
            this.LostFocusCommand = new RelayCommand(LostFocusCommandExecute);
            this.SelectCommand = new RelayCommand(SelectCommandExecute);
            this.CreateToastCommand = new RelayCommand(CreateToastCommandExecute);
            this.UpdateTileCommand = new RelayCommand(UpdateTileCommandExecute);
        }

        private void IncrementCommandExecute()
        {
            this.Number++;
        }

        private void DecrementCommandExecute()
        {
            this.Number--;
        }

        private void MultiplyCommandExecute()
        {
            this.Number *= 2;
        }

        private void DivideCommandExecute()
        {
            this.Number /= 2;
        }

        private void GotFocusCommandExecute()
        {
            this.Caption = "This textbox has got focus, and a command has been executed!!";
        }

        private void LostFocusCommandExecute()
        {
            this.Caption = "This textbox has lost focus, and a command has been executed!!";
        }

        private async void SelectCommandExecute()
        {
            string msg = string.Format("You have selected item : {0}", this.ItemSelected);
            MessageDialog dlg = new MessageDialog(msg);
            await dlg.ShowAsync();
        }

        private void CreateToastCommandExecute()
        {
            string toastId = "id";
            DateTime dt = DateTime.Now.AddSeconds(1);

            //ToastHelper.ScheduleToastText01(toastId, content, dt);
            //ToastHelper.ScheduleToastText02(toastId, firstRow, content, dt);
            //ToastHelper.ScheduleToastText03(toastId, firstRow, content, dt);
            //ToastHelper.ScheduleToastText04(toastId, "first row in bold", "row 1", "row 2", dt);
            //ToastHelper.ScheduleToastImageAndText01(toastId, "Assets/Logo.png", content, dt);
            //ToastHelper.ScheduleToastImageAndText02(toastId, "Assets/Logo.png", "first row in bold", content, dt);
            //ToastHelper.ScheduleToastImageAndText03(toastId, "Assets/Logo.png", "first row in bold", content, dt);
            ToastHelper.ScheduleToastImageAndText04(toastId, "Assets/Logo.png", "first row in bold", "content 1", "content 2", dt);
        }

        private void UpdateTileCommandExecute()
        {
            Random random = new Random((int)DateTime.Now.Ticks);
            int number = random.Next(1, 20);
            //var result = TileHelper.UpdateTileWithNumber(number);
            //var result = TileHelper.CreateSecondaryTile("id", "short Name", "display Name", Windows.UI.StartScreen.TileOptions.ShowNameOnLogo, "Assets/Logo.png").Result;
            //var result = TileHelper.DeleteSecondaryTile("id").Result;
            //TileHelper.UpdateTileSquareBlock(number.ToString(), "small text");
            //TileHelper.UpdateTileSquareText01("header", "first row", "second row", "third row");
            //TileHelper.UpdateTileSquareText02("header", "content that wraps on three lines inside the tile!");
            //TileHelper.UpdateTileSquareText03("first row", "second row", "third row", "fourth row");
            //TileHelper.UpdateTileSquareText04("long content that wraps over 4 lines in this tile");
            //TileHelper.UpdateTileSquareImage("TileUpdated22.png");
            //TileHelper.UpdateTileWideText01("header", "first row", "second row", "third row", "fourth row");
            //TileHelper.UpdateTileWideText02("header", "first row", "second row", "third row", "fourth row", "fifth row", "sixth row", "seventh row", "eighth row");
            //TileHelper.UpdateTileWideText03("super mega content (max 3 lines)");
            //TileHelper.UpdateTileWideText04("super mega content (max 5 lines)");
            //TileHelper.UpdateTileWideText05("first row", "second row", "third row", "fourth row", "fifth row");
            //TileHelper.UpdateTileWideText06("first row", "second row", "third row", "fourth row", "fifth row", "sixth row", "seventh row", "eighth row", "ninth row", "tenth row");
            //TileHelper.UpdateTileWideText07("header", "label 1", "content 1", "label 2", "content 2", "label 3", "content 3", "label 4", "content 4");
            //TileHelper.UpdateTileWideText08("label 1", "content 1", "label 2", "content 2", "label 3", "content 3", "label 4", "content 4", "label 5", "content 5");
            //TileHelper.UpdateTileWideText09("header", "long content that can wrap over 3 lines in this tile");
            //TileHelper.UpdateTileWideText10("header", "l1", "long content 1", "l2", "long content 2", "l3", "long content 3", "l4", "long content 4");
            //TileHelper.UpdateTileWideText11("l1", "long content 1", "l2", "long content 2", "l3", "long content 3", "l4", "long content 4", "l5", "long content 5");
            //TileHelper.UpdateTileWideImage("TileUpdated.png");
            //TileHelper.UpdateTileWideImageCollection("TileUpdated.png", "TileUpdated1.png", "TileUpdated2.png", "TileUpdated3.png", "TileUpdated4.png");
            //TileHelper.UpdateTileWideImageAndText01("TileUpdated2.png", "long content below the image");
            //TileHelper.UpdateTileWideImageAndText02("TileUpdated3.png", "first row below the image", "second row below the image");
            //TileHelper.UpdateTileWideBlockAndText01("first row", "second row", "third row", "fourth row", number.ToString(), "subtitle");
            //TileHelper.UpdateTileWideBlockAndText02("long content that wraps over 4 lines in this tile", number.ToString(), "subtitle");
            //TileHelper.UpdateTileWideSmallImageAndText01("TileUpdated1.png", "content that wraps over 3 lines in this tile");
            //TileHelper.UpdateTileWideSmallImageAndText02("TileUpdated2.png", "header", "first row", "second row", "third row", "fourth row");
            //TileHelper.UpdateTileWideSmallImageAndText03("TileUpdated3.png", "long content that can wraps over 5 lines in this tile");
            //TileHelper.UpdateTileWideSmallImageAndText04("TileUpdated4.png", "header", "content that can wraps over 4 lines in this tile");
            //TileHelper.UpdateTileWideSmallImageAndText05("TileUpdated1.png", "header", "content that can wraps over 4 lines in this tile");
            //TileHelper.UpdateTileWidePeekImageCollection01("TileUpdated.png", "TileUpdated1.png", "TileUpdated2.png", "TileUpdated3.png", "TileUpdated4.png", "header", "content");
            //TileHelper.UpdateTileWidePeekImageCollection02("TileUpdated.png", "TileUpdated1.png", "TileUpdated2.png", "TileUpdated3.png", "TileUpdated4.png", "header", "first row", "second row", "third row", "fourth row");
            //TileHelper.UpdateTileWidePeekImageCollection03("TileUpdated.png", "TileUpdated1.png", "TileUpdated2.png", "TileUpdated3.png", "TileUpdated4.png", "super mega header");
            //TileHelper.UpdateTileWidePeekImageCollection04("TileUpdated.png", "TileUpdated1.png", "TileUpdated2.png", "TileUpdated3.png", "TileUpdated4.png", "this content can wraps over a maximum of 5 lines in this animated live");
            //TileHelper.UpdateTileWidePeekImageCollection05("TileUpdated.png", "TileUpdated1.png", "TileUpdated2.png", "TileUpdated3.png", "TileUpdated4.png", "TileUpdated5.png", "header", "long content that can wraps over 4 lines in this tile");
            //TileHelper.UpdateTileWidePeekImageCollection06("TileUpdated.png", "TileUpdated1.png", "TileUpdated2.png", "TileUpdated3.png", "TileUpdated4.png", "TileUpdated5.png", "long header that can wraps over 3 lines");
            //TileHelper.UpdateTileWidePeekImageAndText01("TileUpdated3.png", "long content that can wraps over 5 lines");
            //TileHelper.UpdateTileWidePeekImageAndText02("TileUpdated1.png", "first row", "second row", "third row", "fourth row", "fifth row");
            //TileHelper.UpdateTileWidePeekImage01("TileUpdated5.png", "header", "long content that can wraps over 4 lines in this tile");
            //TileHelper.UpdateTileWidePeekImage02("TileUpdated5.png", "header", "first row", "second row", "third row", "fourth row");
            //TileHelper.UpdateTileWidePeekImage03("TileUpdated4.png", "long header that can wraps over 3 lines");
            //TileHelper.UpdateTileWidePeekImage04("TileUpdated.png", "long content that can wraps over 5 lines");
            //TileHelper.UpdateTileWidePeekImage05("TileUpdated3.png", "TileUpdated1.png", "header", "long content that can wraps over 4 lines");
            //TileHelper.UpdateTileWidePeekImage06("TileUpdated1.png", "TileUpdated.png", "header that can wraps over 3 lines");

            //TileHelper.UpdateTileSquarePeekImageAndText01("TileUpdated.png", "header", "first row", "second row", "third row");
            //TileHelper.UpdateTileSquarePeekImageAndText02("TileUpdated2.png", "header", "content");
            //TileHelper.UpdateTileSquarePeekImageAndText03("TileUpdated3.png", "first row", "second row", "third row", "fourth row");
            TileHelper.UpdateTileSquarePeekImageAndText04("TileUpdated4.png", "long content");
        }
    }
}